/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "tskcfg.h"
#include "bsp.h"
#include "storage.h"
#include "spiflash.h"
#include "route.h"
#include "ctrl_common.h"

volatile Sys_DebugSwitchType Sys_DebugSwitch = 
{
  .net_tx_pl = 0,
  .net_tx_tp = 0,
  .net_rx_pl = 0,
  .net_rx_tp = 0,
};

const Sys_VersionType Sys_Version = 
{
#if (COLLECTOR_USE_TYPE == COLLECTOR_USE_NTC)
	.collecter_type = COLLECTOR_USE_NTC,
#elif (COLLECTOR_USE_TYPE == COLLECTOR_USE_LORA)
	.collecter_type = COLLECTOR_USE_LORA,
#else
	#error must define COLLECTOR_USE_TYPE in bsp.h.
#endif
	
  .routever = ROUTE_VERSION,

#if (VFD_VER == 710)
  .vfd_ver = "710",
#elif (VFD_VER == 720)
  .vfd_ver = "720",
#else
  #error must define VFD_VER in bsp.h.
#endif
  
	.ver   = "V5.3.3",
	.bdata = __DATE__" "__TIME__,
};

void dog(void)
{
  rcu_osci_on(RCU_IRC32K);
  
  /* wait till IRC32K is ready */
  while(SUCCESS != rcu_osci_stab_wait(RCU_IRC32K))
  {
  }
  
  /* confiure FWDGT counter clock: 32KHz(IRC32K) / 64 = 0.5 KHz */
  fwdgt_config(0x0FFFu, FWDGT_PSC_DIV256);
  
  /* After 2 seconds to generate a reset */
  fwdgt_enable();
}

int main(void)
{
	SysHal_Init();
	
	dog();
	
	_printf("\r\nAPP is Running......\r\n");
	_printf("App version  : %s\r\n", Sys_Version.ver);
#if (COLLECTOR_USE_TYPE == COLLECTOR_USE_NTC)
	_printf("CollecterType: NTC\r\n");
#elif (COLLECTOR_USE_TYPE == COLLECTOR_USE_LORA)
	_printf("CollecterType: LoRa\r\n");
#else
	#error must define COLLECTOR_USE_TYPE in bsp.h.
#endif
  _printf("Route version: %d\r\n", Sys_Version.routever);
  _printf("VFD version  : %s\r\n", Sys_Version.vfd_ver);
	_printf("Build Data   : %s\r\n", Sys_Version.bdata);
	
	Storage_Parameter();
	
  APP_CreateTask();
	
  /* Start scheduler */
  vTaskStartScheduler();
 
  /* We should never get here as control is now taken by the scheduler */
  while (1)
  {
  }
}



#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{ 
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
